home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 January / PCWorld_2007-01_cd.bin / v cisle / autoit / autoit-v3.2.0.1-setup.exe / Examples / Helpfile / GUICtrlCreateTreeView.au3 < prev    next >
Text File  |  2006-07-25  |  4KB  |  93 lines

  1. #include <GUIConstants.au3>
  2.  
  3. GUICreate("My GUI with treeview", 350, 215)
  4.  
  5. $treeview       = GUICtrlCreateTreeView(6, 6, 100, 150, BitOr($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
  6. $generalitem    = GUICtrlCreateTreeViewitem("General", $treeview)
  7. GUICtrlSetColor(-1, 0x0000C0)
  8. $displayitem    = GUICtrlCreateTreeViewitem("Display", $treeview)
  9. GUICtrlSetColor(-1, 0x0000C0)
  10. $aboutitem      = GUICtrlCreateTreeViewitem("About", $generalitem)
  11. $compitem       = GUICtrlCreateTreeViewitem("Computer", $generalitem)
  12. $useritem       = GUICtrlCreateTreeViewitem("User", $generalitem)
  13. $resitem        = GUICtrlCreateTreeViewitem("Resolution", $displayitem)
  14. $otheritem      = GUICtrlCreateTreeViewitem("Other", $displayitem)
  15.  
  16. $startlabel     = GUICtrlCreateLabel("TreeView Demo",190,90,100,20)
  17. $aboutlabel     = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60)
  18. GUICtrlSetState(-1, $GUI_HIDE)  ; Hides the "aboutlabel"-text during initialization
  19. $compinfo       = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @LF & "OS:" & @TAB & @OSVersion & @LF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80)
  20. GUICtrlSetState(-1, $GUI_HIDE)  ; Hides the "compinfo"-text during initialization
  21.  
  22. GUICtrlCreateLabel("", 0, 170, 350, 2, $SS_SUNKEN)
  23. $togglebutton   = GUICtrlCreateButton("&Toggle", 35, 185, 70, 20)
  24. $infobutton     = GUICtrlCreateButton("&Info", 105, 185, 70, 20)
  25. $statebutton    = GUICtrlCreateButton("Col./Exp.", 175, 185, 70, 20)
  26. $cancelbutton   = GUICtrlCreateButton("&Cancel", 245, 185, 70, 20)
  27.  
  28. GUICtrlSetState($generalitem, BitOr($GUI_EXPAND,$GUI_DEFBUTTON))    ; Expand the "General"-item and paint in bold
  29. GUICtrlSetState($displayitem, BitOr($GUI_EXPAND,$GUI_DEFBUTTON))    ; Expand the "Display"-item and paint in bold
  30.  
  31. GUISetState ()
  32. While 1
  33.     $msg = GUIGetMsg()
  34.     Select
  35.         Case $msg = $cancelbutton Or $msg = $GUI_EVENT_CLOSE
  36.             ExitLoop
  37.     
  38.         Case $msg = $togglebutton   ; Toggle the bold painting
  39.             If BitAnd(GUICtrlRead($generalitem), $GUI_DEFBUTTON) Then
  40.                 GUICtrlSetState($generalitem, 0)
  41.                 GUICtrlSetState($displayitem, 0)
  42.             Else
  43.                 GUICtrlSetState($generalitem, $GUI_DEFBUTTON)
  44.                 GUICtrlSetState($displayitem, $GUI_DEFBUTTON)
  45.             EndIf
  46.         
  47.         Case $msg = $infobutton
  48.             $item = GUICtrlRead($treeview)      ; Get the controlID of the current selected treeview item
  49.             If $item = 0 Then
  50.                 MsgBox(64, "TreeView Demo", "No item currently selected")
  51.             Else
  52.                 $text = GUICtrlRead($item, 1) ; Get the text of the treeview item
  53.                 If $text == "" Then
  54.                     MsgBox(16, "Error", "Error while retrieving infos about item")
  55.                 Else
  56.                     MsgBox(64, "TreeView Demo", "Current item selected is: " & $text)  ; $advmsg[0] contains the text and $advmsg[1] the state value of the treeview item
  57.                 EndIf
  58.             EndIf
  59.             
  60.         Case $msg = $statebutton
  61.             $item = GUICtrlRead($treeview)
  62.             If $item > 0 Then
  63.                 $hItem = GUICtrlGetHandle($item)
  64.                 GuiCtrlSendMsg($treeview, $TVM_EXPAND, $TVE_TOGGLE, $hItem)
  65.             EndIf
  66.             
  67.         ; The following items will hide the other labels (1st and 2nd parameter) and then show the 'own' labels (3rd and 4th parameter)
  68.         Case $msg = $generalitem
  69.             GUIChangeItems($aboutlabel, $compinfo, $startlabel, $startlabel)
  70.         
  71.         Case $msg = $aboutitem
  72.             GUICtrlSetState ($compinfo, $GUI_HIDE)
  73.             GUIChangeItems($startlabel, $startlabel, $aboutlabel, $aboutlabel)
  74.             
  75.         Case $msg = $compitem
  76.             GUIChangeItems($startlabel, $aboutlabel, $compinfo, $compinfo)
  77.     EndSelect
  78. WEnd
  79.  
  80. GUIDelete()
  81. Exit
  82.  
  83. Func GUIChangeItems($hidestart, $hideend, $showstart, $showend)
  84.     Local $idx
  85.     
  86.     For $idx = $hidestart To $hideend
  87.         GUICtrlSetState ($idx, $GUI_HIDE)
  88.     Next
  89.     For $idx = $showstart To $showend
  90.         GUICtrlSetState ($idx, $GUI_SHOW)
  91.     Next    
  92. EndFunc
  93.